<?php
// +----------------------------------------------------------------------
// |  [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\meeting\controller;

use cmf\controller\AdminBaseController;
use function Sodium\increment;
use think\Db;

class Checkpicture2Controller extends AdminBaseController
{


    /*
     * 租赁服务列表
     * */
    public function index()
    {
        $where=[];
        $where[]=['title','like','%'. input('keyword','') .'%'];
        $data = Db::table('ims_hc_meet')
            ->where($where)
            ->paginate(10);
        $page  =  $data->render();
        $list  = $data->toArray();

        $this->assign('list',$list['data']);
        $this->assign('page',$page);
        return $this->fetch();

    }

    /*
   * lists
   * @param
   * $return
   */
    public function lists()
    {
        if(input('meeting_id')){
            session('MEETING_ID',input('meeting_id'));
        }
        $where[] = ['meeting_id','=', session('MEETING_ID')];
        $where[] = ['number','like', '%'.input('number','').'%'];
        $data  =  Db::table('ims_hc_meet_room_check_picture')
            ->where($where)
            ->paginate();
        $page  =  $data->render();
        $list  = $data->toArray();

        $this->assign('list',$list['data']);
        $this->assign('page',$page);
        return $this->fetch();
    }

    /*
     * check
     * @param
     * $return
     */
    public function check()
    {
        if($this->request->isPost()){
            $data = input();
            $id     = $data['id'];
            $updatedata = [];
            $updatedata['status'] = $data['status'];
            $updatedata['reason'] = $data['reason'];
            $updatedata['update_time'] = time();
            if( $data['status'] ==2 && empty($data['reason'])){
                $this->error('请填写拒绝理由');
            }
            $result = Db::table('ims_hc_meet_room_check_picture')->where(['id' => $id])->update($updatedata);
            if ($result) {
                $this->success('成功');exit();
            } else {
                $this->error('失败');
            }
        }

    }

    /*
     * detail
     * @param
     * $return
     */
    public function detail()
    {
        $id = input('id');
        $list       = Db::table('ims_hc_meet_room_check_picture')->find($id);
        if ($list){
            $list['content'] = empty($list['content'])?[]: json_decode($list['content'],1);
            $list['content2'] = empty($list['content2'])?[]: json_decode($list['content2'],1);
            $list['content3'] = empty($list['content3'])?[]: json_decode($list['content3'],1);
            $list['content4'] = empty($list['content4'])?[]: json_decode($list['content4'],1);
            $list['content5'] = empty($list['content5'])?[]: json_decode($list['content5'],1);
            $list['content6'] = empty($list['content6'])?[]: json_decode($list['content6'],1);
            $list['content7'] = empty($list['content7'])?[]: json_decode($list['content7'],1);
        }

        $status = [
            0=>'待审核',
            1=>'已通过',
            2=>'已拒绝',
        ];
        $this->assign('list',$list);
        $this->assign('status',$status);
        return $this->fetch();
    }

}
